import java.util.Calendar;
/* PlayCounter
 * 
 * toggle the 'stop' command in improvise every 4000 ms ... to simulate turn taking.
 * 
 */

import javax.xml.bind.JAXBException;

public class PlayCounter_ extends Thread {
	public Object[] oscArray;
	public void run(){
		while (true)
		{

			if (Main.improvise.stop&&!Main.stillPlaying)
			{

				oscArray = new Object[] {"BREATHING"};
				OSC.main(oscArray,"/head-commands");
			}
			
			if (Main.improvise.stop&&Main.stillPlaying)
			{

				oscArray = new Object[] {"BANG"};
				OSC.main(oscArray,"/head-commands");
			}

			if (Main.improvise.stop&&Main.stillPlaying)
			{

				Main.improvise.stop=false;
				Main.learning=false;
				try {
					Main.improvise.start();
				} catch (JAXBException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			else 
			{

				Main.improvise.stop=true;
				Main.stillPlaying=false;
				Main.learning=true;
				
			}



			try {
				if (Main.improvise.stop)
				{
					System.out.println("LEARNING");
					oscArray = new Object[] {"LISTEN"};
					OSC.main(oscArray,"/head-commands");
					Thread.sleep(1500);					
					if (!Main.stillPlaying)
					{

						oscArray = new Object[] {"BREATHING"};
						OSC.main(oscArray,"/head-commands");
					}
					Thread.sleep(5000);

					}
				else
				{
					oscArray = new Object[] {"PLAY"};
					OSC.main(oscArray,"/head-commands");
					System.out.println("PLAYING");
					Thread.sleep(8500);
				}
			} 
			catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
